<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>FastDFS</title>
    <!--<script src="jquery.form.js" type="text/javascript"></script>-->
    <script src="js/jquery.min.js" type="text/javascript"></script>
    <script>
        function upload(form){
            if(form.file.value=='') {
                alert("请选择文件!");
                form.file.focus();
                return false;
            }
            var formData = new FormData(document.getElementById("form"));
            console.log(form);
            function upload(form){
                if(form.file.value=='') {
                    alert("请选择文件!");
                    form.file.focus();
                    return false;
                }
                var formData = new FormData(document.getElementById("form"));
                console.log(form);
                $.ajax({
                    url:"/file/uploadFile",
                    type:"post",
                    data:formData,
                    cache: false,
                    processData: false,
                    contentType: false,
                    success:function(data){
                        var type = data.type;
                        if (type == "image") {
                            var image = "<img src="+data.pathInfo+" style='padding:30px' width='500px' height='400px' />"
                            $("#img").append(image);
                            alert("上传图片成功!");
                        }else if (type == "file"){
                            alert("上传文件成功!");
                        }else if (type == "media"){
                            alert("上传视频成功!");
                            var url = "index.html?url="+data.pathInfo+"&type="+data.ext;
                            window.open(url,"newwindow", "height=600, width=800, top=300, left=400, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no");
                        }
                        else{
                            alert("上传成功!");
                        }
                    },
                    error:function(e){
                        alert(e);
                    }
                });
            }
        }
    </script>

</head>
<body>

<form id="form" action="/pic/uploadPic" method="post" enctype="multipart/form-data">
    <label>文件</label><input type="file" name="file" id="file"/><br/>
    <input type="button" onclick="upload(this.form)" value="提  交"/>
</form>
<label>图片</label><br>
<div  id="img" />
</body>
</html>